package com.example.ywj.http.http;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.ywj.http.R;

import java.util.List;

public class UserAdapter extends BaseAdapter {

    private List<User> list;
    public UserAdapter(List<User> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView == null){
            LayoutInflater inflater = LayoutInflater.from(parent.getContext());
            convertView = inflater.inflate(R.layout.item,null);
            viewHolder = new ViewHolder();
            viewHolder.tv1 = convertView.findViewById(R.id.item_user);
            viewHolder.tv2 = convertView.findViewById(R.id.item_pwd);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder)convertView.getTag();
        }
        viewHolder.tv1.setText(list.get(position).getUsername());
        viewHolder.tv2.setText(list.get(position).getPassword());
        return convertView;
    }
    class ViewHolder{
        private TextView tv1;
        private TextView tv2;
    }
}
